home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / bin2dec.arc / BIN2DEC.C next >
Encoding:
C/C++ Source or Header  |  1985-09-06  |  1.1 KB  |  59 lines

  1.  
  2. #include <stdio.h>
  3.  
  4. /****************************************************************
  5. *                                *
  6. *            - makedb -                *
  7. *                                *
  8. *       Convert a binary file to a bunch of DB's        *
  9. *             for an assembler.                *
  10. *                                *
  11. *        T. Jennings 25 Oct. 82                *
  12. *                                *
  13. ****************************************************************/
  14.  
  15.  
  16. main(argc,argv)
  17. int argc;
  18. char **argv;
  19. {
  20. int infile;
  21. unsigned i;
  22. int column;
  23. char data;
  24.  
  25.     printf("\nMake DB's from a binary file to <stdout>\n");
  26.     printf(" T. Jennings 25 Oct. 82\n");
  27.  
  28.     if (argc < 2) {
  29.         printf("Must supply a file name!\n");
  30.         exit(1);
  31.     }
  32.     infile= open(argv[1],0x8000);
  33.     if (infile == -1 ) {
  34.         printf("Can't find %s\n",argv[1]);
  35.         exit(1);
  36.     }
  37.     column= 80;
  38.     while (read(infile,&data,1) ) {
  39.         if (column > 28) {
  40.             printf("\n\tdb\t");
  41.             column= 0;
  42.         }
  43.         if (column > 0) 
  44.             printf(",");
  45.         printf("%u",data);
  46.  
  47. /* KLUDGE: Guess the length of the thing we just typed, so we can keep
  48. the columns neat. */
  49.         i= data;
  50.         column+=2;        /* count the comma, 1's digit, */
  51.         if(i > 10)
  52.             ++column;    /* tens, */
  53.         if (i > 100)
  54.             ++ column;    /* 100's */
  55.     }
  56.     printf("\n");
  57.     exit(0);
  58. }
  59.